package com.jie.controller;
import com.jie.dto.ArticleDTO;
import com.jie.po.req.ArticleReq;
import com.jie.response.RespBean;
import com.jie.service.IArticleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 论坛文章表 前端控制器
 * </p>
 *
 * @author jie
 * @since 2024-05-29
 */
@Api(tags = "论坛文章模块")
@RestController
@RequestMapping("/article")
public class ArticleController {

    @Autowired
    private IArticleService articleService;
    /**
     * 1.填写文章信息，选择标签，选择分类，上传文章封面，上传文章内容，提交审核
     * 2.处理文章图片和视频信息 需要提前处理 处理完成后再进行发布阶段
     * 3.审核通过后进行发布
     */
    /**
     * 添加文章
     *
     * @param article 文章信息
     * @return {@link RespBean<>}
     */

    @ApiOperation(value = "添加文章")
    @PostMapping("/add")
    public RespBean<?> addArticle(@Validated @RequestBody ArticleReq article) {
        articleService.addArticle(article);
        return RespBean.success("保存成功，等待审核后发布或保存至草稿箱");
    }
    @ApiOperation(value = "获取文章列表(包括评论资源)")
    @GetMapping("/get/articleList")
    public  RespBean<?> getArticleList() {
        List<ArticleDTO> articleAndCommentDTO=articleService.getArticleList();
        return RespBean.success("查询文章列表成功^v^",articleAndCommentDTO);
    }
    @ApiOperation(value = "重新编辑文章")
    @PostMapping("/update/article")
    public   RespBean<?> updateArticle(@Validated @RequestBody ArticleReq article) {
        return RespBean.success();
    }

    @ApiOperation(value = "增加文章的评论数")
    @PostMapping("/add/article/CommentCount")
    public   RespBean<?> addArticleCommentCount(@RequestParam(value = "articleId")Integer articleId,
                                                @RequestParam(value = "commentCount")Integer commentCount) {
        return RespBean.success("增加文章评论数成功",articleService.addArticleCommentCount(articleId,commentCount));
    }

}

